package com.cbs.android.extension.webviewclient;

import android.graphics.Bitmap;

/**
 * Created by broche on 4/28/16.
 */
public class WebViewClient extends android.webkit.WebViewClient {
    public void onCBSPageStarted(android.webkit.WebView view, String url, Bitmap favicon) {
    }

    public final void onPageStarted(android.webkit.WebView view, String url, Bitmap favicon) {
        onCBSPageStarted(view, url, favicon);
        int width = view.getWidth();
        float ratio = view.getContext().getResources().getDisplayMetrics().density;
        if (!url.contains("cbswidth")) {
            if (url.contains("?")) {
                url = String.format("%s&cbswidth=%s&cbsratio=%f", url, width, ratio);
            } else {
                url = String.format("%s?cbswidth=%s&cbsratio=%f", url, width, ratio);
            }
            view.loadUrl(url);
            return;
        }
        super.onPageStarted(view, url, favicon);
    }
}
